#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
CRM后端服务启动脚本
"""

import os
import uvicorn

# 设置开发环境变量
os.environ.setdefault('SECRET_KEY', 'crm-development-secret-key-change-in-production-minimum-32-chars')
os.environ.setdefault('DEBUG', 'true')
os.environ.setdefault('DATABASE_URL', 'sqlite+aiosqlite:///./data/crm.db')
os.environ.setdefault('HOST', '127.0.0.1')
os.environ.setdefault('PORT', '8000')


def main():
    """启动FastAPI服务器"""

    print("=" * 60)
    print("🚀 启动CRM旅游管理系统后端服务")
    print("=" * 60)
    print("📱 API文档地址: http://127.0.0.1:8000/docs")
    print("📊 备用文档地址: http://127.0.0.1:8000/redoc")
    print("💚 健康检查地址: http://127.0.0.1:8000/health")
    print("🔗 API基础地址: http://127.0.0.1:8000/api")
    print("=" * 60)
    print("按 Ctrl+C 停止服务")
    print("=" * 60)

    try:
        # 启动服务器
        uvicorn.run(
            "src.app:app",
            host="127.0.0.1",
            port=8000,
            reload=True,
            log_level="info",
            access_log=True
        )
    except KeyboardInterrupt:
        print("\n👋 服务已停止")
    except Exception as e:
        print(f"❌ 服务启动失败: {e}")
        import traceback
        traceback.print_exc()


if __name__ == "__main__":
    main()
